﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dominion_Established
{
    class Menus
    {
        public static int NUM_CITIES = 1;
        public static City[] cities;
        public static bool isRunning = true;
        public static int textColorCounter = 0;
        public static int selectedColorCounter = 0;
        public static ConsoleColor textColor()
        {
            ConsoleColor color;
            color = ConsoleColor.White;
            switch (textColorCounter)
            {
                case 0:
                    color = ConsoleColor.White;
                    break;
                case 1:
                    color = ConsoleColor.Blue;
                    break;
                case 2:
                    color = ConsoleColor.Green;
                    break;
                case 3:
                    color = ConsoleColor.Yellow;
                    break;
                case 4:
                    color = ConsoleColor.Red;
                    break;
                case 5:
                    color = ConsoleColor.Gray;
                    break;
                case 6:
                    color = ConsoleColor.Cyan;
                    break;
            }
            return color;
        }
        public static ConsoleColor selectedTextColor()
        {
            ConsoleColor color;
            color = ConsoleColor.Green;
            switch (selectedColorCounter)
            {
                case 0:
                    color = ConsoleColor.Green;
                    break;
                case 1:
                    color = ConsoleColor.Blue;
                    break;
                case 2:
                    color = ConsoleColor.White;
                    break;
                case 3:
                    color = ConsoleColor.Yellow;
                    break;
                case 4:
                    color = ConsoleColor.Red;
                    break;
                case 5:
                    color = ConsoleColor.Gray;
                    break;
                case 6:
                    color = ConsoleColor.Cyan;
                    break;
            }
            return color;
        }
        public static void MainMenu()
        {
            ConsoleKeyInfo input;
            int menuOpt = 0;
            while (isRunning)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Clear();
                Console.WriteLine("Dominion Established v1.1");
                Console.WriteLine();
                string[] menuItems = { "New Game", "Load Game", "Options", "Manual", "Credits", "Quit" };
                for (int i = 0; i < menuItems.Length; i++)
                {
                    
                    if (menuOpt == i)
                    {
                        Console.ForegroundColor = selectedTextColor();
                        Console.WriteLine(menuItems[i]);
                    }
                    else
                    {
                        Console.ForegroundColor = textColor();
                        Console.WriteLine(menuItems[i]);
                    }
                }
                input = Console.ReadKey(true);
                switch (input.Key)
                {
                    case ConsoleKey.DownArrow:
                        if (menuOpt != (menuItems.Length - 1))
                        {
                            menuOpt++;
                        }
                        break;
                    case ConsoleKey.UpArrow:
                        if (menuOpt != 0)
                        {
                            menuOpt--;
                        }
                        break;
                    case ConsoleKey.Enter:
                        switch (menuOpt)
                        {
                            case 0:
                                isRunning = false;
                                NewGameScreen();
                                break;
                            case 1:
                                isRunning = false;
                                LoadGameScreen();
                                break;
                            case 2:
                                isRunning = false;
                                OptionsScreen();
                                break;
                            case 3:
                                isRunning = false;
                                ManualScreen();
                                break;
                            case 4:
                                isRunning = false;
                                CreditsScreen();
                                break;
                            case 5:
                                isRunning = false;
                                Environment.Exit(0);
                                break;
                        }
                        break;
                }
                
            }
        }
        public static void NewGameScreen()
        {
            Console.Clear();
            cities = new City[NUM_CITIES];
            cities[0] = new City("Default", 0, 0, 0, 0, 0);
            Console.ForegroundColor = textColor();
            Console.WriteLine("What is the name of your first city?");
            cities[0].Name = Console.ReadLine();
            isRunning = true;
            GameScreen();
        }
        public static void LoadGameScreen()
        {

        }
        public static void OptionsScreen()
        {
            ConsoleKeyInfo input;
            int menuOpt = 0;
            string[] menuItems = { "Selected Text Color", "Unselected Text Color", "Back" };
            isRunning = true;
            while (isRunning)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Options");
                Console.WriteLine();
                for (int i = 0; i < menuItems.Length; i++)
                {
                    if (menuOpt == i)
                    {
                        Console.ForegroundColor = selectedTextColor();
                        Console.WriteLine(menuItems[i]);
                    }
                    else
                    {
                        Console.ForegroundColor = textColor();
                        Console.WriteLine(menuItems[i]);
                    }
                }
                input = Console.ReadKey(true);
                switch (input.Key)
                {
                    case ConsoleKey.DownArrow:
                        if (menuOpt != (menuItems.Length - 1))
                        {
                            menuOpt++;
                        }
                        break;
                    case ConsoleKey.UpArrow:
                        if (menuOpt != 0)
                        {
                            menuOpt--;
                        }
                        break;
                    case ConsoleKey.Enter:
                        switch (menuOpt)
                        {
                            #region New Selected Text Color
                            case 0:
                                menuOpt = 0;
                                while (isRunning)
                                {
                                    string[] selectedTextColorOptions = { "Green", "Blue", "White", "Yellow", "Red", "Grey", "Cyan", "Back" };
                                    Console.Clear();
                                    for (int i = 0; i < selectedTextColorOptions.Length; i++)
                                    {
                                        if (menuOpt == i)
                                        {
                                            Console.ForegroundColor = selectedTextColor();
                                            Console.WriteLine(selectedTextColorOptions[i]);
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = textColor();
                                            Console.WriteLine(selectedTextColorOptions[i]);
                                        }
                                    }
                                    input = Console.ReadKey(true);
                                    switch (input.Key)
                                    {
                                        case ConsoleKey.DownArrow:
                                            if (menuOpt != (selectedTextColorOptions.Length - 1))
                                            {
                                                menuOpt++;
                                            }
                                            break;
                                        case ConsoleKey.UpArrow:
                                            if (menuOpt != 0)
                                            {
                                                menuOpt--;
                                            }
                                            break;
                                        case ConsoleKey.Enter:
                                            switch (menuOpt)
                                            {
                                                case 0:
                                                    selectedColorCounter = 0;
                                                    break;
                                                case 1:
                                                    selectedColorCounter = 1;
                                                    break;
                                                case 2:
                                                    selectedColorCounter = 2;
                                                    break;
                                                case 3:
                                                    selectedColorCounter = 3;
                                                    break;
                                                case 4:
                                                    selectedColorCounter = 4;
                                                    break;
                                                case 5:
                                                    selectedColorCounter = 5;
                                                    break;
                                                case 6:
                                                    selectedColorCounter = 6;
                                                    break;
                                                case 7:
                                                    isRunning = false;
                                                    break;
                                            }
                                            break;

                                    }
                                }
                                menuOpt = 0;
                                isRunning = true;
                                break;
                            #endregion
                            #region New Unselected Text Color
                            case 1:
                                menuOpt = 0;
                                while (isRunning)
                                {
                                    string[] selectedTextColorOptions = { "White", "Blue", "Green", "Yellow", "Red", "Grey", "Cyan", "Back" };
                                    Console.Clear();
                                    for (int i = 0; i < selectedTextColorOptions.Length; i++)
                                    {
                                        if (menuOpt == i)
                                        {
                                            Console.ForegroundColor = selectedTextColor();
                                            Console.WriteLine(selectedTextColorOptions[i]);
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = textColor();
                                            Console.WriteLine(selectedTextColorOptions[i]);
                                        }
                                    }
                                    input = Console.ReadKey(true);
                                    switch (input.Key)
                                    {
                                        case ConsoleKey.DownArrow:
                                            if (menuOpt != (selectedTextColorOptions.Length - 1))
                                            {
                                                menuOpt++;
                                            }
                                            break;
                                        case ConsoleKey.UpArrow:
                                            if (menuOpt != 0)
                                            {
                                                menuOpt--;
                                            }
                                            break;
                                        case ConsoleKey.Enter:
                                            switch (menuOpt)
                                            {
                                                case 0:
                                                    textColorCounter = 0;
                                                    break;
                                                case 1:
                                                    textColorCounter = 1;
                                                    break;
                                                case 2:
                                                    textColorCounter = 2;
                                                    break;
                                                case 3:
                                                    textColorCounter = 3;
                                                    break;
                                                case 4:
                                                    textColorCounter = 4;
                                                    break;
                                                case 5:
                                                    textColorCounter = 5;
                                                    break;
                                                case 6:
                                                    textColorCounter = 6;
                                                    break;
                                                case 7:
                                                    isRunning = false;
                                                    break;
                                            }
                                            break;

                                    }
                                }
                                menuOpt = 0;
                                isRunning = true;
                                break;
                            #endregion
                            case 2:
                                MainMenu();
                                break;
                        }
                        break;
                }
                
            }
        }
        public static void ManualScreen()
        {

        }
        public static void CreditsScreen()
        {
            Console.ForegroundColor = textColor();
            Console.Clear();
            Console.WriteLine("This game was created by: ");
            Console.WriteLine("Tyler Kirk,");
            Console.WriteLine("and Cam Herringshaw.");
            Console.WriteLine();
            Console.WriteLine("Dominion Established was made entirely in C Sharp without any wrappers, \nlibraries, or engines.");
            Console.WriteLine();
            Console.WriteLine("If you would like to contribute to future versions of Dominion Established, \nsend a request to:");
            Console.WriteLine("DreamDesigns882@gmail.com");
            Console.WriteLine();
            Console.WriteLine("To join Dream Designs, the company that made this game, you must know a \nbit of C Sharp first!");
            Console.WriteLine();
            Console.WriteLine("<Press Any Key to Return to the Main Menu>");
            Console.ReadKey(true);
            isRunning = true;
            MainMenu();

        }
        public static void GameScreen()
        {
            ConsoleKeyInfo input;
            int menuOpt = 0;
            string[] mainMenuItems = { "End Turn", "Construction" };
            while (isRunning)
            {
                Console.Clear();
                Console.ForegroundColor = textColor();
                Console.WriteLine("Dominion Established");
                Console.WriteLine();
                for (int i = 0; i < mainMenuItems.Length; i++)
                {
                    if (menuOpt == i)
                    {
                        Console.ForegroundColor = selectedTextColor();
                        Console.WriteLine(mainMenuItems[i]);
                    }
                    else
                    {
                        Console.ForegroundColor = textColor();
                        Console.WriteLine(mainMenuItems[i]);
                    }
                }
                input = Console.ReadKey(true);
                switch (input.Key)
                {
                    case ConsoleKey.DownArrow:
                        if (menuOpt != (mainMenuItems.Length - 1))
                        {
                            menuOpt++;
                        }
                        break;
                    case ConsoleKey.UpArrow:
                        if (menuOpt != 0)
                        {
                            menuOpt--;
                        }
                        break;
                    case ConsoleKey.Enter:
                        switch (menuOpt)
                        {
                            #region End Turn
                            case 0: //End Turn
                                break;
                            #endregion
                            #region Construction
                            case 1: // Construction
                                menuOpt = 0;
                                while (isRunning)
                                {
                                    Console.Clear();
                                    Console.ForegroundColor = textColor();
                                    Console.WriteLine("Dominion Established");
                                    Console.WriteLine(">Construct");
                                    Console.WriteLine();
                                    string[] gameItemsConstruction = { "Construct General Buildings", 
                                                                         "Construct Special Buildings", 
                                                                         "Construct Utilities", 
                                                                         "Construct Transportation Methodes",
                                                                         "View Construction Statistics",
                                                                         "View Transporation Statistics",
                                                                         "Back" };
                                    for (int i = 0; i < gameItemsConstruction.Length; i++)
                                    {
                                        if (menuOpt == i)
                                        {
                                            Console.ForegroundColor = selectedTextColor();
                                            Console.WriteLine(gameItemsConstruction[i]);
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = textColor();
                                            Console.WriteLine(gameItemsConstruction[i]);
                                        }
                                    }
                                    input = Console.ReadKey(true);
                                    switch (input.Key)
                                    {
                                        case ConsoleKey.DownArrow:
                                            if (menuOpt != (gameItemsConstruction.Length - 1))
                                            {
                                                menuOpt++;
                                            }
                                            break;
                                        case ConsoleKey.UpArrow:
                                            if (menuOpt != 0)
                                            {
                                                menuOpt--;
                                            }
                                            break;
                                        case ConsoleKey.Enter:
                                            switch (menuOpt)
                                            {
                                                #region Construct General Buildings
                                                case 0:
                                                    menuOpt = 0;
                                                    string[] gameItemsConstructGeneralBuildings = { "Residential", "Commercial", "Industrial", "Back" };
                                                    while (isRunning)
                                                    {
                                                        Console.Clear();
                                                        Console.ForegroundColor = textColor();
                                                        Console.WriteLine("Dominion Established");
                                                        Console.WriteLine(">>Construct General Buildings");
                                                        Console.WriteLine();
                                                        for (int i = 0; i < gameItemsConstructGeneralBuildings.Length; i++)
                                                        {
                                                            if (menuOpt == i)
                                                            {
                                                                Console.ForegroundColor = selectedTextColor();
                                                                Console.WriteLine(gameItemsConstructGeneralBuildings[i]);
                                                            }
                                                            else
                                                            {
                                                                Console.ForegroundColor = textColor();
                                                                Console.WriteLine(gameItemsConstructGeneralBuildings[i]);
                                                            }
                                                        }
                                                        input = Console.ReadKey(true);
                                                        switch (input.Key)
                                                        {
                                                            case ConsoleKey.DownArrow:
                                                                if (menuOpt != (gameItemsConstructGeneralBuildings.Length - 1))
                                                                {
                                                                    menuOpt++;
                                                                }
                                                                break;
                                                            case ConsoleKey.UpArrow:
                                                                if (menuOpt != 0)
                                                                {
                                                                    menuOpt--;
                                                                }
                                                                break;
                                                            case ConsoleKey.Enter:
                                                                switch (menuOpt)
                                                                {
                                                                    case 0:
                                                                        
                                                                        break;
                                                                    case 1:
                                                                        break;
                                                                    case 2:
                                                                        break;
                                                                    case 3:
                                                                        break;
                                                                }
                                                                break;
                                                        }   
                                                
                                                    }
                                                    break;
                                                #endregion
                                                case 1:
                                                    break;
                                                case 2:
                                                    break;
                                                case 3:
                                                    break;
                                                case 4:
                                                    break;
                                                case 5:
                                                    break;
                                                case 6:
                                                    isRunning = false;
                                                    break;
                                            }
                                            break;
                                    }
                                }
                                menuOpt = 0;
                                isRunning = true;
                                break;
                        }
                        break;
                            #endregion
                }
            }
            
        }
    }
}
